<!doctype html>
<title>Test changing focus inside plugin onfocus and onblur events</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>

<input id="input1" type="text" onfocus="i1Focus()" onblur="i1Blur()"></input>
<input id="input2" type="text" onfocus="i2Focus()" onblur="i2Blur()"></input>
<input id="input3" type="text" onfocus="i3Focus()" onblur="i3Blur()"></input>
<input id="input4" type="text" onfocus="i4Focus()" onblur="i4Blur()"></input>
<embed id="plugin" type="application/x-blink-test-plugin" onfocus="pFocus()" onblur="pBlur()"></embed>

<script>
let events = [];
function i1Focus() { events.push('i1focus'); }
function i1Blur() { events.push('i1blur'); }
function i2Focus() { events.push('i2focus'); }
function i2Blur() { events.push('i2blur'); }
function i3Focus() { events.push('i3focus'); } 
function i3Blur() { events.push('i3blur'); }
function i4Focus() { events.push('i4focus'); } 
function i4Blur() { events.push('i4blur'); }
function pFocus() {
  events.push('pfocus-change-2');
  document.getElementById('input2').focus();
}
function pBlur() {
  events.push('pblur-change-4');
  document.getElementById('input4').focus();
}

async_test(t => {
  function finish() {
    assert_array_equals(events, ["i1focus","i1blur","pfocus-change-2","pblur-change-4","i4focus","i4blur","i3focus"]);
    t.done();
  }
  document.getElementById('input1').focus();
  document.getElementById('plugin').focus();
  document.getElementById('input3').focus();

  t.step_timeout(finish, 0);
},"Test plugin focus behavior");

</script>
